'''
Created on 28.05.2011

@author: blaze
'''

class WikiPage(object):
    '''
    classdocs
    '''
    
    def __init__(self, name, version, text, time, author, comment):
        self.name = name
        self.version = version
        self.text = text
        self.time = time
        self.author = author
        self.comment = comment

    def __str__(self):
        return self.name + "[" + str(self.version) + "@" + self.author + "]"
        
    def __lt__(self, other):
        return self.version < other.version
    def __gt__(self, other):
        return self.version > other.version
    def __eq__(self, other):
        return self.version == other.version
    def __le__(self, other):
        return self.version <= other.version
    def __ge__(self, other):
        return self.version >= other.version
    def __ne__(self, other):
        return self.version != other.version
        
class WikiPages(object):
    
    #TODO:
    # - add filter (f.e. filter pages by trac user)
    # - add user mapping
    def __init__(self):
        self.pages = {}
        self.counter = 0
         
    def addPage(self, wikiPage):
        self.counter += 1
        
        if wikiPage.name in self.pages:
            self.pages[wikiPage.name].append(wikiPage)
        else: 
            self.pages[wikiPage.name] = [wikiPage,]
    
    def getPagesName(self):
        return self.pages.keys()
    
    def getPageVersions(self, wikiPageName):
        pageVersions = self.pages.get(wikiPageName)
        pageVersions.sort()
        return pageVersions

    def printStat(self):
        print("Total pages: %i" % len(self.pages))
        print("Total entity: %i" % self.counter)
        
if __name__ == "__main__":
    pages = WikiPages()    
    pages.addPage(WikiPage('index', '2', '', '22', 'blaze', 'test'))
    pages.addPage(WikiPage('index', '1', '', '11', 'blaze', 'test'))

    for page in pages.getPagesName():
        print (page)
        for pageVer in pages.getPageVersions(page):            
            print ("\t%s" % pageVer)
    pages.printStat()
